package com.tl.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tl.common.annotation.Log;
import com.tl.common.core.controller.BaseController;
import com.tl.common.core.domain.AjaxResult;
import com.tl.common.enums.BusinessType;
import com.tl.app.domain.AppGift;
import com.tl.app.service.IAppGiftService;
import com.tl.common.utils.poi.ExcelUtil;
import com.tl.common.core.page.TableDataInfo;

/**
 * 礼物Controller
 * 
 * @author suhp
 * @date 2024-06-21
 */
@RestController
@RequestMapping("/app/gift")
public class AppGiftController extends BaseController
{
    @Autowired
    private IAppGiftService appGiftService;

    /**
     * 查询礼物列表
     */
    @PreAuthorize("@ss.hasPermi('app:gift:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppGift appGift)
    {
        startPage();
        List<AppGift> list = appGiftService.selectAppGiftList(appGift);
        return getDataTable(list);
    }

    /**
     * 导出礼物列表
     */
    @PreAuthorize("@ss.hasPermi('app:gift:export')")
    @Log(title = "礼物", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppGift appGift)
    {
        List<AppGift> list = appGiftService.selectAppGiftList(appGift);
        ExcelUtil<AppGift> util = new ExcelUtil<AppGift>(AppGift.class);
        util.exportExcel(response, list, "礼物数据");
    }

    /**
     * 获取礼物详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:gift:query')")
    @GetMapping(value = "/{giftId}")
    public AjaxResult getInfo(@PathVariable("giftId") Long giftId)
    {
        return success(appGiftService.selectAppGiftByGiftId(giftId));
    }

    /**
     * 新增礼物
     */
    @PreAuthorize("@ss.hasPermi('app:gift:add')")
    @Log(title = "礼物", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppGift appGift)
    {
        return toAjax(appGiftService.insertAppGift(appGift));
    }

    /**
     * 修改礼物
     */
    @PreAuthorize("@ss.hasPermi('app:gift:edit')")
    @Log(title = "礼物", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppGift appGift)
    {
        return toAjax(appGiftService.updateAppGift(appGift));
    }

    /**
     * 删除礼物
     */
    @PreAuthorize("@ss.hasPermi('app:gift:remove')")
    @Log(title = "礼物", businessType = BusinessType.DELETE)
	@DeleteMapping("/{giftIds}")
    public AjaxResult remove(@PathVariable Long[] giftIds)
    {
        return toAjax(appGiftService.deleteAppGiftByGiftIds(giftIds));
    }
}
